﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Reflection;
using System.Linq;
namespace PPFinance.Common
{
    public class AssemblyAction
    {
        /// <summary>
        /// 得到一个Assembly
        /// </summary>
        /// <param name="assemblyName">程序集名称（可模糊）</param>
        /// <returns></returns>
        public static Assembly GetAssembly(string assemblyName)
        {
            var assFilter = PPFinance.UI.Static.ClientVariable.ClientAssembly.Where(p => p.FullName.Contains(assemblyName));
            if (assFilter.Any())
            {
                var ass = assFilter.Single();
                if (ass != null)
                {
                    return ass;
                }
            }
            return null;
        }
        public static dynamic GetObject(string assemblyName, string typeName, params object[] paramers)
        {
            var ass = GetAssembly(assemblyName);
            if (ass != null)
            {
                var type = ass.GetType(typeName);
                if (type != null)
                {
                    string funName = typeName;
                    if (typeName.IndexOf('.') > 0)
                    {
                        var temp = typeName.Split('.');
                        funName = temp[temp.Length - 1];
                    }
                    var obj = type.InvokeMember(funName, BindingFlags.CreateInstance, null, null, paramers);
                    return obj;
                }
            }
            return null;
        }
    }
}
